package com.forlove.app.qselect.friend.presenter;

import android.text.TextUtils;

import com.forlove.app.common.network.ICallBack;
import com.forlove.app.common.utils.ParseHelper;
import com.forlove.app.manager.NetworkManager;
import com.forlove.app.manager.ServerManager;
import com.forlove.app.qselect.CommonEntity;
import com.forlove.app.qselect.friend.entity.FriendAskEntity;
import com.forlove.app.qselect.friend.service.IFriendAskService;
import com.forlove.app.qselect.friend.service.impl.FriendAskServiceImpl;
import com.forlove.app.qselect.friend.view.FriendAskView;

import java.util.HashMap;

/**
 * Created by yjl on 2017/11/25.
 */

public class FriendAskPresenter extends MineNewFriendPresenter {
    private IFriendAskService friendAskService;
    private FriendAskView friendAskView;

    public FriendAskPresenter(FriendAskView mineNewFriendView) {
        super(mineNewFriendView);
        this.friendAskView = mineNewFriendView;
        friendAskService = new FriendAskServiceImpl();
        setService(friendAskService);
    }

    public void loadAskFriendData() {
        friendAskService.loadData(ServerManager.ACTION_FRIEND_REQUEST, new HashMap(), new ICallBack() {
            @Override
            public void onSuccess(int statusCode, String result) {
                FriendAskEntity friendAskEntity = ParseHelper.getModel(result, "data", FriendAskEntity.class);
                friendAskView.updateAskFriendView(friendAskEntity);
            }

            @Override
            public void onFail(int statusCode, String result) {
                CommonEntity commonEntity = new CommonEntity();
                commonEntity.parseJSONString(result);
                if (!TextUtils.isEmpty(commonEntity.message)) {
                    friendAskView.showErrorData(NetworkManager.ResultCode.RESULT_FAIL, commonEntity.message);
                } else {
                    friendAskView.showErrorData(NetworkManager.ResultCode.RESULT_ERROR, "稍后重试!");
                }
            }
        });
    }
}
